package com.maket.scxx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maket.scxx.domain.CpflProductClassification;
import com.maket.scxx.feign.GetCodeFeign;
import com.maket.scxx.mapper.CpflProductClassificationMapper;
import com.maket.scxx.service.CpflProductClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.maket.scxx.domain.QxDefect;
import com.maket.scxx.service.IQxDefectService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 缺陷定义Controller
 * 
 * @author ruoyi
 * @date 2024-06-24
 */
@RestController
@RequestMapping("/qxdy")
public class QxDefectController extends BaseController
{
    @Autowired
    private IQxDefectService qxDefectService;

    /**
     * 查询缺陷定义列表
     */
    @RequiresPermissions("scxx:qxdy:list")
    @GetMapping("/list")
    public TableDataInfo list(QxDefect qxDefect)
    {
        startPage();
        List<QxDefect> list = qxDefectService.selectQxDefectList(qxDefect);
        return getDataTable(list);
    }

    /**
     * 查询产品分类列表
     */
    @Autowired
    private CpflProductClassificationService cpflProductClassificationService;
    @RequiresPermissions("scxx:qxdy:list")
    @GetMapping("/getCpfl")
    public TableDataInfo getCpfl(CpflProductClassification cpflProductClassification)
    {
        startPage();
        List<CpflProductClassification> list = cpflProductClassificationService.getAll(cpflProductClassification);
        return getDataTable(list);
    }

    /**
     * 导出缺陷定义列表
     */
    @RequiresPermissions("scxx:qxdy:export")
    @Log(title = "缺陷定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QxDefect qxDefect)
    {
        List<QxDefect> list = qxDefectService.selectQxDefectList(qxDefect);
        ExcelUtil<QxDefect> util = new ExcelUtil<QxDefect>(QxDefect.class);
        util.exportExcel(response, list, "缺陷定义数据");
    }

    /**
     * 获取缺陷定义详细信息
     */
    @RequiresPermissions("scxx:qxdy:query")
    @GetMapping(value = "/{defectCode}")
    public AjaxResult getInfo(@PathVariable("defectCode") String defectCode)
    {
        return success(qxDefectService.selectQxDefectByDefectCode(defectCode));
    }

    /**
     * 新增缺陷定义
     */
    @Autowired
    private GetCodeFeign getCodeFeign;
    @RequiresPermissions("scxx:qxdy:add")
    @Log(title = "缺陷定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QxDefect qxDefect)
    {
        String code = getCodeFeign.getUser(13);
        qxDefect.setDefectCode(code);
        return toAjax(qxDefectService.insertQxDefect(qxDefect));
    }

    /**
     * 修改缺陷定义
     */
    @RequiresPermissions("scxx:qxdy:edit")
    @Log(title = "缺陷定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QxDefect qxDefect)
    {
        return toAjax(qxDefectService.updateQxDefect(qxDefect));
    }

    /**
     * 删除缺陷定义
     */
    @RequiresPermissions("scxx:qxdy:remove")
    @Log(title = "缺陷定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{defectCodes}")
    public AjaxResult remove(@PathVariable String[] defectCodes)
    {
        return toAjax(qxDefectService.deleteQxDefectByDefectCodes(defectCodes));
    }
}
